/*
 * @Author: wuyuxin
 * @Date: 2022-02-07 20:40:45
 * @LastEditors: wuyuxin
 * @LastEditTime: 2022-02-07 22:57:07
 * @Description: 
 */

import axios from 'axios'
// 创建axios实例
const service = axios.create({
  // baseURL: store.get(`SUB_APP_${name}`),
  // baseURL: '/fbk',
  baseURL: process.env.VUE_APP_BASE_API, // api的base_url
  timeout: 300 * 1000 // 请求超时时间 5分钟
})

// request拦截器
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    Promise.reject(error)
  }
)

// response 拦截器
service.interceptors.response.use(
  async response => {
    return response
  },
  error => {
    if (error.toString().includes('401')) {
      return Promise.reject(new Error('error'))
    } else if (error.toString().includes('404')) {
      console.error(error.message)
    } else if (error.toString().includes('500')) {
      console.error(error.message)
    } else if (error.response && error.response.data && error.response.data.msg) {
      console.error(error.message)
    } else {
      console.error(error.message)
    }
    return Promise.reject(error)
  }
)
export default service
